﻿namespace WGController32_CSharp
{
    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Drawing;
    using System.Windows.Forms;
    using WG3000_COMM.Core;

    public class dfrmNetControllerConfig : Form
    {
        private Button btnConfigure;
        private Button btnExit;
        private Button btnSearch;
        private IContainer components;
        private DataGridView dgvFoundControllers;
        private DataGridViewTextBoxColumn f_ControllerSN;
        private DataGridViewTextBoxColumn f_Gateway;
        private DataGridViewTextBoxColumn f_ID;
        private DataGridViewTextBoxColumn f_IP;
        private DataGridViewTextBoxColumn f_MACAddr;
        private DataGridViewTextBoxColumn f_Mask;
        private DataGridViewTextBoxColumn f_PCIPAddr;
        private Label label1;
        private Label lblCount;
        private Label lblSearchNow;

        public dfrmNetControllerConfig()
        {
            this.InitializeComponent();
        }

        private void btnConfigure_Click(object sender, EventArgs e)
        {
            if (this.dgvFoundControllers.SelectedRows.Count > 0)
            {
                using (dfrmTCPIPConfigure configure = new dfrmTCPIPConfigure())
                {
                    DataGridViewRow row = this.dgvFoundControllers.SelectedRows[0];
                    configure.strSN = row.Cells["f_ControllerSN"].Value.ToString();
                    configure.strMac = row.Cells["f_MACAddr"].Value.ToString();
                    configure.strIP = row.Cells["f_IP"].Value.ToString();
                    configure.strMask = row.Cells["f_Mask"].Value.ToString();
                    configure.strGateway = row.Cells["f_Gateway"].Value.ToString();
                    string str = "";
                    if (row.Cells["f_PCIPAddr"].Value != null)
                    {
                        str = row.Cells["f_PCIPAddr"].Value.ToString();
                    }
                    configure.strPCAddr = str;
                    if (configure.ShowDialog(this) == DialogResult.OK)
                    {
                        MessageBox.Show("请重新搜索...");
                    }
                }
            }
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            base.Close();
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            this.lblCount.Text = "0";
            this.Cursor = Cursors.WaitCursor;
            this.dgvFoundControllers.Rows.Clear();
            this.btnConfigure.Enabled = false;
            ArrayList arrController = new ArrayList();
            using (wgMjController controller = new wgMjController())
            {
                controller.SearchControlers(ref arrController);
            }
            if (arrController != null)
            {
                if (arrController.Count <= 0)
                {
                    MessageBox.Show("Not Found");
                    this.btnConfigure.Enabled = true;
                    return;
                }
                this.dgvFoundControllers.Rows.Clear();
                for (int i = 0; i < arrController.Count; i++)
                {
                    string[] strArray = arrController[i].ToString().Split(new char[] { ',' });
                    string[] strArray3 = new string[7];
                    int num2 = this.dgvFoundControllers.Rows.Count + 1;
                    strArray3[0] = num2.ToString().PadLeft(4, '0');
                    strArray3[1] = strArray[0];
                    strArray3[2] = strArray[1];
                    strArray3[3] = strArray[2];
                    strArray3[4] = strArray[3];
                    strArray3[5] = strArray[4];
                    strArray3[6] = strArray[5];
                    string[] values = strArray3;
                    this.dgvFoundControllers.Rows.Add(values);
                }
            }
            this.btnSearch.Enabled = true;
            if (this.dgvFoundControllers.Rows.Count > 0)
            {
                this.btnConfigure.Enabled = true;
            }
            this.lblCount.Text = this.dgvFoundControllers.Rows.Count.ToString();
            this.Cursor = Cursors.Default;
        }

        private void dfrmNetControllerConfig_Load(object sender, EventArgs e)
        {
            this.btnConfigure.Enabled = false;
        }

        private void dgvFoundControllers_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (this.btnConfigure.Enabled)
            {
                this.btnConfigure.PerformClick();
            }
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            ComponentResourceManager manager = new ComponentResourceManager(typeof(dfrmNetControllerConfig));
            DataGridViewCellStyle style = new DataGridViewCellStyle();
            DataGridViewCellStyle style2 = new DataGridViewCellStyle();
            this.btnSearch = new Button();
            this.btnConfigure = new Button();
            this.btnExit = new Button();
            this.dgvFoundControllers = new DataGridView();
            this.label1 = new Label();
            this.lblCount = new Label();
            this.lblSearchNow = new Label();
            this.f_ID = new DataGridViewTextBoxColumn();
            this.f_ControllerSN = new DataGridViewTextBoxColumn();
            this.f_IP = new DataGridViewTextBoxColumn();
            this.f_Mask = new DataGridViewTextBoxColumn();
            this.f_Gateway = new DataGridViewTextBoxColumn();
            this.f_MACAddr = new DataGridViewTextBoxColumn();
            this.f_PCIPAddr = new DataGridViewTextBoxColumn();
            ((ISupportInitialize) this.dgvFoundControllers).BeginInit();
            base.SuspendLayout();
            this.btnSearch.BackColor = Color.Transparent;
            manager.ApplyResources(this.btnSearch, "btnSearch");
            this.btnSearch.ForeColor = Color.Black;
            this.btnSearch.Name = "btnSearch";
            this.btnSearch.UseVisualStyleBackColor = false;
            this.btnSearch.Click += new EventHandler(this.btnSearch_Click);
            this.btnConfigure.BackColor = Color.Transparent;
            manager.ApplyResources(this.btnConfigure, "btnConfigure");
            this.btnConfigure.ForeColor = Color.Black;
            this.btnConfigure.Name = "btnConfigure";
            this.btnConfigure.UseVisualStyleBackColor = false;
            this.btnConfigure.Click += new EventHandler(this.btnConfigure_Click);
            this.btnExit.BackColor = Color.Transparent;
            manager.ApplyResources(this.btnExit, "btnExit");
            this.btnExit.ForeColor = Color.Black;
            this.btnExit.Name = "btnExit";
            this.btnExit.UseVisualStyleBackColor = false;
            this.btnExit.Click += new EventHandler(this.btnExit_Click);
            this.dgvFoundControllers.AllowUserToAddRows = false;
            this.dgvFoundControllers.AllowUserToDeleteRows = false;
            manager.ApplyResources(this.dgvFoundControllers, "dgvFoundControllers");
            this.dgvFoundControllers.BackgroundColor = SystemColors.Window;
            style.Alignment = DataGridViewContentAlignment.MiddleCenter;
            style.BackColor = Color.FromArgb(0x7c, 0x7d, 0x9c);
            style.Font = new Font("宋体", 9f, FontStyle.Regular, GraphicsUnit.Point, 0x86);
            style.ForeColor = Color.White;
            style.SelectionBackColor = SystemColors.Highlight;
            style.SelectionForeColor = SystemColors.HighlightText;
            style.WrapMode = DataGridViewTriState.True;
            this.dgvFoundControllers.ColumnHeadersDefaultCellStyle = style;
            this.dgvFoundControllers.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
            this.dgvFoundControllers.Columns.AddRange(new DataGridViewColumn[] { this.f_ID, this.f_ControllerSN, this.f_IP, this.f_Mask, this.f_Gateway, this.f_MACAddr, this.f_PCIPAddr });
            this.dgvFoundControllers.EnableHeadersVisualStyles = false;
            this.dgvFoundControllers.Name = "dgvFoundControllers";
            this.dgvFoundControllers.ReadOnly = true;
            this.dgvFoundControllers.RowHeadersVisible = false;
            this.dgvFoundControllers.RowTemplate.Height = 0x17;
            this.dgvFoundControllers.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
            this.dgvFoundControllers.Tag = "已搜索到控制器";
            this.dgvFoundControllers.MouseDoubleClick += new MouseEventHandler(this.dgvFoundControllers_MouseDoubleClick);
            manager.ApplyResources(this.label1, "label1");
            this.label1.BackColor = Color.Transparent;
            this.label1.ForeColor = Color.Black;
            this.label1.Name = "label1";
            manager.ApplyResources(this.lblCount, "lblCount");
            this.lblCount.BackColor = Color.Transparent;
            this.lblCount.ForeColor = Color.Black;
            this.lblCount.Name = "lblCount";
            manager.ApplyResources(this.lblSearchNow, "lblSearchNow");
            this.lblSearchNow.BackColor = Color.Transparent;
            this.lblSearchNow.ForeColor = Color.Black;
            this.lblSearchNow.Name = "lblSearchNow";
            manager.ApplyResources(this.f_ID, "f_ID");
            this.f_ID.Name = "f_ID";
            this.f_ID.ReadOnly = true;
            style2.Alignment = DataGridViewContentAlignment.MiddleRight;
            this.f_ControllerSN.DefaultCellStyle = style2;
            manager.ApplyResources(this.f_ControllerSN, "f_ControllerSN");
            this.f_ControllerSN.Name = "f_ControllerSN";
            this.f_ControllerSN.ReadOnly = true;
            manager.ApplyResources(this.f_IP, "f_IP");
            this.f_IP.Name = "f_IP";
            this.f_IP.ReadOnly = true;
            manager.ApplyResources(this.f_Mask, "f_Mask");
            this.f_Mask.Name = "f_Mask";
            this.f_Mask.ReadOnly = true;
            manager.ApplyResources(this.f_Gateway, "f_Gateway");
            this.f_Gateway.Name = "f_Gateway";
            this.f_Gateway.ReadOnly = true;
            manager.ApplyResources(this.f_MACAddr, "f_MACAddr");
            this.f_MACAddr.Name = "f_MACAddr";
            this.f_MACAddr.ReadOnly = true;
            manager.ApplyResources(this.f_PCIPAddr, "f_PCIPAddr");
            this.f_PCIPAddr.Name = "f_PCIPAddr";
            this.f_PCIPAddr.ReadOnly = true;
            manager.ApplyResources(this, "$this");
            base.Controls.Add(this.lblCount);
            base.Controls.Add(this.label1);
            base.Controls.Add(this.lblSearchNow);
            base.Controls.Add(this.dgvFoundControllers);
            base.Controls.Add(this.btnExit);
            base.Controls.Add(this.btnConfigure);
            base.Controls.Add(this.btnSearch);
            base.Name = "dfrmNetControllerConfig";
            base.Load += new EventHandler(this.dfrmNetControllerConfig_Load);
            ((ISupportInitialize) this.dgvFoundControllers).EndInit();
            base.ResumeLayout(false);
            base.PerformLayout();
        }
    }
}

